<?php declare(strict_types=1);
/**
 * @author      xianganyall <xianganyall@gmail.com>
 * @copyright   2023-2025 owner
 **/

namespace Srv\Apps\Apis\Common\DefCtl;

use Srv\Libs\Frame\RequestHeader;

final class DefPlatformCtl extends DefAbstract
{
    private const TABLE_NAME                = 'def_platform';
    private const FIELD_ID                  = 'ddpt_id';
    private const FIELD_KEY                 = 'ddpt_key';
    private const FIELD_NAME                = 'ddpt_name';
    private const FIELD_DDPTID_LIST         = 'ddpt_id_list';
    public const EXT_DDPTID_JSON            = 'ddptIdJson';
    public const EXT_NAME                   = 'name';
    public const KEY_ANDROID                = 'android';        // 安卓 - 手机版
    public const KEY_IOS                    = 'ios';            // 苹果 - 手机版
    public const KEY_ANDROID_PAD            = 'android_pad';    // 安卓 - 平板版
    public const KEY_IOS_PAD                = 'ios_pad';        // 苹果 - 平板版
    public const KEY_WEB_IN_APP             = 'web_in_app';     // 网页 - 应用内嵌
    public const KEY_WEB_MOBILE             = 'web_mobile';     // 网页 - 移动浏览器
    public const KEY_WEB_PC                 = 'web_pc';         // 网页 - 电脑浏览器
    public const KEY_WEB_H5                 = 'web_h5';         // 网页 - H5

    /**
     * @return static
     * tag
     */
    public static function tag():self
    {
        $fieldExtList       = [
            self::EXT_DDPTID_JSON   => self::FIELD_DDPTID_LIST,
            self::EXT_NAME          => self::FIELD_NAME,
        ];
        return parent::tag()->config(self::TABLE_NAME, self::FIELD_ID, self::FIELD_KEY, $fieldExtList);
    }

    /**
     * @return bool
     * isAndroid
     */
    public function isAndroid():bool
    {
        return in_array(RequestHeader::getAppPlatform(), [self::KEY_ANDROID, self::KEY_ANDROID_PAD], true);
    }

    /**
     * @return bool
     * isIos
     */
    public function isIos():bool
    {
        return in_array(RequestHeader::getAppPlatform(), [self::KEY_IOS, self::KEY_IOS_PAD], true);
    }
}